<template>
  <el-dialog
    :close-on-click-modal="false"
    :title="isEdit ? '修改' : '新增'"
    width="800px"
    :visible.sync="visible"
  >
    <el-form :model="form" ref="form" :label-position="labelPosition" label-width="120px">
      <el-row :gutter="24">
        <div v-if=" type === 'now' ">
          <el-col>
            <el-form-item label="房屋地址">
              <el-input v-model="form.houseAdr" placeholder="请输入房屋地址" />
            </el-form-item>
          </el-col>
          <el-col>
            <el-form-item label="建筑面积">
              <el-input v-model="form.houseFloorage" placeholder="请输入建筑面积" />
            </el-form-item>
          </el-col>
          <el-col>
            <el-form-item label="房屋性质">
              <el-input v-model="form.houseNature" placeholder="请输入房屋性质" />
            </el-form-item>
          </el-col>
          <el-col>
            <el-form-item label="产权人">
              <el-input v-model="form.houseOwner" placeholder="请输入产权人" />
            </el-form-item>
          </el-col>
          <el-col>
            <el-form-item label="自住房屋来源">
              <el-input v-model="form.houseSource" placeholder="请输入自住房屋来源" />
            </el-form-item>
          </el-col>
          <el-col>
            <el-form-item label="其他情况">
              <el-input v-model="form.otherRemark" placeholder="请输入其他情况" />
            </el-form-item>
          </el-col>
          <el-col>
            <el-form-item label="备注">
              <el-input v-model="form.remark" placeholder="请输入备注" />
            </el-form-item>
          </el-col>
        </div>
        <div v-if="type !== 'now'">
          <el-col>
            <el-form-item label="房屋地址">
              <el-input v-model="form.adr" placeholder="请输入房屋地址" />
            </el-form-item>
          </el-col>
          <el-col>
            <el-form-item label="建筑面积">
              <el-input v-model="form.floorage" placeholder="请输入建筑面积" />
            </el-form-item>
          </el-col>
          <el-col v-if="type !== 'build'">
            <el-form-item label="房屋性质">
              <el-input v-model="form.nature" placeholder="请输入房屋性质" />
            </el-form-item>
          </el-col>
        </div>

        <div v-if="type === 'buy'">
          <el-col>
            <el-form-item label="购房时间">
              <el-date-picker
                type="date"
                :style="inputWidth"
                format="yyyy-MM-dd"
                value-format="yyyy-MM-dd"
                v-model="form.buyDate"
                placeholder="请选择"
              />
            </el-form-item>
          </el-col>
          <el-col>
            <el-form-item label="购房金额">
              <el-input v-model="form.buyMoney" :min="0" type="number" />
            </el-form-item>
          </el-col>
        </div>

        <div v-if="type === 'sale'">
          <el-col>
            <el-form-item label="售房时间">
              <el-date-picker
                type="date"
                :style="inputWidth"
                format="yyyy-MM-dd"
                value-format="yyyy-MM-dd"
                v-model="form.saleDate"
                placeholder="请选择"
              />
            </el-form-item>
          </el-col>
          <el-col>
            <el-form-item label="售房金额">
              <el-input v-model="form.saleMoney" :min="0" type="number" />
            </el-form-item>
          </el-col>
        </div>
        <div v-if="type === 'rent'">
          <el-col>
            <el-form-item label="租赁期限">
              <el-date-picker
                :style="inputWidth"
                type="daterange"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                format="yyyy-MM-dd"
                value-format="yyyy-MM-dd"
                v-model="form.deadline"
                placeholder="请选择"
              />
            </el-form-item>
          </el-col>
          <el-col>
            <el-form-item label="年租金">
              <el-input v-model="form.yearMoney" :min="0" type="number" />
            </el-form-item>
          </el-col>
        </div>
        <div v-if=" type === 'build' ">
          <el-col>
            <el-form-item label="集资单位">
              <el-input v-model="form.buildUnit" />
            </el-form-item>
          </el-col>
          <el-col>
            <el-form-item label="房款总额">
              <el-input v-model="form.buildMoney" :min="0" type="number" />
            </el-form-item>
          </el-col>
          <el-col>
            <el-form-item label="个人支付">
              <el-input v-model="form.invest" :min="0" type="number" />
            </el-form-item>
          </el-col>
        </div>
      </el-row>
    </el-form>
    <div slot="footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="handleUpdate">{{ isEdit ? '修改' : '新增' }}</el-button>
    </div>
  </el-dialog>
</template>

<script>
export default {
  data() {
    return {
      visible: false,
      inputWidth: {
        width: '100%'
      },
      labelPosition: 'right',
      form: {},
      isEdit: false,
      type: null
    }
  },
  methods: {
    edit(bool, row, type) {
      this.visible = true
      this.isEdit = bool
      this.type = type
      this.form = Object.assign({}, row)
    },
    handleUpdate() {
      this.$refs.form.validate(async valid => {
        if (valid) {
          //   if (!this.isEdit) {
          this.visible = false
          console.log('form', this.form, this.type)
          this.$emit('refresh', this.form, this.type, this.isEdit)
          //   }
        }
      })
    }
  }
}
</script>

<style>
</style>